#include "widget.h"
#include "ui_widget.h"
#include "customlistview.h"
#include "twocolumndelegate.h"

#include <QHBoxLayout>
#include <QLabel>
#include <QStringListModel>
// QStyledItemDelegateTest [master]
Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QStringListModel* model = new QStringListModel(this) ;
    QStringList items;
    items << "F101 |Computer    |我的电脑                      |::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
          << "F0   |Explorer    |资源管理器                    |explorer.exe /e,::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
          << "F1   |MyDocument  |我的文档                      |explorer.exe"
          << "F9   |ie          |IE浏览器                      |iexplore.exe";

    model -> setStringList(items);

    // 直接使用stringListModel作为QAbstractItemModel
    // QAbstractItemModel* abstractModel = model;
    // 创建自定义列表视图
    listView = new CustomListView(this);
    listView->setModel(model);
    TwoColumnDelegate *delegate = new TwoColumnDelegate(this);
    listView->setItemDelegate(delegate);


    // 设置布局
    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addWidget(listView);
    setLayout(layout);
}

Widget::~Widget()
{
    delete ui;
}
